package com.ecommerce.model;

public class Product {
    // 商品ID
    private int id;
    // 商品名称
    private String name;
    // 商品描述
    private String description;
    // 商品价格
    private double price;
    // 库存数量
    private int stockQuantity;
    private int lowStockThreshold;
    // 分类ID
    private int categoryId;
    // 分类名称
    private String categoryName;
    // 商品状态（active/inactive）
    private String status;

    public Product() {}

    public Product(String name, String description, double price, int stockQuantity, int categoryId) {
        this.name = name;
        this.description = description;
        this.price = price;
        this.stockQuantity = stockQuantity;
        this.categoryId = categoryId;
        this.lowStockThreshold = 10;
    }

    // Getters and Setters
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }

    public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }

    public int getStockQuantity() { return stockQuantity; }
    public void setStockQuantity(int stockQuantity) { this.stockQuantity = stockQuantity; }

    public int getLowStockThreshold() { return lowStockThreshold; }
    public void setLowStockThreshold(int lowStockThreshold) { this.lowStockThreshold = lowStockThreshold; }
    public int getCategoryId() { return categoryId; }
    public void setCategoryId(int categoryId) { this.categoryId = categoryId; }

    public String getCategoryName() { return categoryName; }
    public void setCategoryName(String categoryName) { this.categoryName = categoryName; }

    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }

    // 检查是否低库存
    public boolean isLowStock() {
        return stockQuantity <= lowStockThreshold;
    }
    // 获取库存状态
    public String getStockStatus() {
        if (stockQuantity == 0) {
            return "缺货";
        } else if (isLowStock()) {
            return "低库存";
        } else {
            return "充足";
        }
    }

    @Override
    public String toString() {
        return String.format("ID: %d | 商品: %s | 价格: ¥%.2f | 库存: %d | 分类: %s",
                id, name, price, stockQuantity,
                categoryName != null ? categoryName : "未分类");
    }

    public String toDetailedString() {
        return String.format(
                "商品ID: %d\n名称: %s\n描述: %s\n价格: ¥%.2f\n库存: %d\n库存状态: %s\n低库存阈值: %d\n分类: %s\n状态: %s",
                id, name, description, price, stockQuantity,getStockStatus(),
                lowStockThreshold,
                categoryName != null ? categoryName : "未分类",
                "active".equals(status) ? "上架" : "下架");
    }
}
